package cz.fi.muni.pb138.spring2013.dtd2xsd.entities;

import cz.fi.muni.pb138.spring2013.dtd2xsd.visitor.interfaces.IDocument;
import cz.fi.muni.pb138.spring2013.dtd2xsd.visitor.interfaces.Visitor;

/**
 * This class represents a "handle" on a document that is being constructed from
 * the parsed DTD.
 *
 * @author Slavomir Krupa
 */
public class Document implements IDocument {

    private ElementRestriction root;
    private String XMLContent;

    @Override
    public void accept(Visitor visitor) {
        if (root == null) {
            throw new NullPointerException("Document root is not set.");
        }
        visitor.visit(this);
        root.accept(visitor);
    }

    public String getXMLContent() {
        return XMLContent;
    }

    public void setXMLContent(String XMLContent) {
        this.XMLContent = XMLContent;
    }

    public ElementRestriction getRoot() {
        return root;
    }

    public void setRoot(ElementRestriction root) {
        this.root = root;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 41 * hash + (this.root != null ? this.root.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Document other = (Document) obj;
        if (this.root != other.root && (this.root == null || !this.root.equals(other.root))) {
            return false;
        }
        return true;
    }
}
